package almacen;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuBar;
import net.atlanticbb.tantlinger.shef.HTMLEditorPane;
import net.atlanticbb.tantlinger.ui.text.actions.HTMLEditorActionFactory;
import net.atlanticbb.tantlinger.ui.text.actions.HTMLFontColorAction;
import net.atlanticbb.tantlinger.ui.text.actions.HTMLImageAction;
import net.atlanticbb.tantlinger.ui.text.actions.HTMLLinkAction;
import org.jsoup.Jsoup;
import resources.local_connection;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author pato
 */
public class Especificaciones extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    
    int code = 1016;
    HTMLEditorPane editor = new HTMLEditorPane();
    public Especificaciones(int cd) {
        initComponents();
        code = cd;
        new HTMLFontColorAction();
new HTMLLinkAction();
new HTMLImageAction();
        
        jPanel1.add(editor);
        JMenuBar menuBar = new JMenuBar();
menuBar.add(editor.getEditMenu());
menuBar.add(editor.getFormatMenu());
menuBar.add(editor.getInsertMenu());
this.setJMenuBar(menuBar);
        jPanel1.updateUI();
        cargarDatos();
    }
//public class cargarDatos extends Thread {
void cargarDatos(){ 
//   @Override
   // public void run() {
        PreparedStatement ps;
        String especificaciones="";
        try {
            ps = local_connection.getconnect().prepareStatement("select especificaciones from productos where id_producto = ?");
        ps.setInt(1,code);
        ResultSet rs = ps.executeQuery();
        rs.next();
        especificaciones=(rs.getObject(1)==null)?"":rs.getString(1);
         especificaciones =Jsoup.parse(especificaciones).text();
        editor.setText(especificaciones);
        
        } catch (SQLException ex) {
Almacen.logger.log(Level.SEVERE, null, ex);       // }
    }
}

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setLayout(new java.awt.GridLayout(1, 0));

        jButton1.setText("Guardar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
PreparedStatement ps;
        try {
            String detalles="";
            ps = local_connection.getconnect().prepareStatement("update productos set especificaciones = ? where id_producto = ?");
        detalles=editor.getText().replaceAll("'", "\\'");
        detalles = detalles.replaceAll("\"","&quote;");
        ps.setString(1,detalles);
        ps.setInt(2,code);
        ps.execute();
        this.dispose();
                } catch (SQLException ex) {
Almacen.logger.log(Level.SEVERE, null, ex);        }
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
